<template>
  <div class="madp-down-page">
    <img src="@/assets/img/download.jpg" alt="" srcset="" />
    <div class="DownBox">
      <div class="btn" @click="download">立即下载</div>
      <span>如未安装请点击下载</span>
      <span>如已安装未自动跳转，请<a class="colorBlue" :href="'hrxjpmbank://' + hrefUrl">刷新</a></span>
    </div>
    <AlertCom ref="myAlertConfirm" @userBehavior="userBehavior"></AlertCom>
  </div>
</template>
<script>
import AlertCom from '@/components/alertCom.vue'
import CallApp from 'callapp-lib'
import * as Utils from '@/utils/util'
let Base64 = require('js-base64').Base64
export default {
  components: { AlertCom },
  data() {
    return {
      hrefUrl: '',
      PrdCode: ''
    }
  },
  created() {},
  mounted() {},
  activated() {
    this.productInfo = JSON.parse(this.$route.query.prodInfo)
    this.prodType = this.$route.query.prodType
    if (this.prodType == 1) {
      // 理财
      let obj = {
        ProductName: this.productInfo.name,
        ProductCode: this.productInfo.code,
        ManagerId: this.$store.state.vuex_wxUserId
      }
      this.hrefUrl = `financeDetail?productInfo=${Base64.encode(encodeURI(JSON.stringify(obj)))}`
    } else if (this.prodType == 2) {
      // 基金
      let obj = {
        ProductName: this.productInfo.name,
        ProductCode: this.productInfo.code,
        ManagerId: this.$store.state.vuex_wxUserId
      }
      this.hrefUrl = `fundDetail?productInfo=${Base64.encode(encodeURI(JSON.stringify(obj)))}`
    } else if (this.prodType == 3) {
      // 幸福通知存
      this.hrefUrl = `WeekHome?`
    } else if (this.prodType == 4) {
      // 整存整取：
      this.hrefUrl = `ZczqHome?`
    } else if (this.prodType == 5) {
      // 通知存款
      this.hrefUrl = `depositHome?`
    } else if (this.prodType == 6) {
      // 零存整取
      this.hrefUrl = `LczqHome?`
    }
    this.checkIsInstalledApp()
  },
  methods: {
    checkIsInstalledApp() {
      console.log('app===', this.hrefUrl)
      var _this = this
      const options = {
        scheme: {
          protocol: 'hrxjpmbank'
        },
        initent: {
          package: 'com.csii.hrxj',
          scheme: 'hrxjpmbank'
        },
        appstore: 'https://apps.apple.com/cn/app/id896945783', //app store下载地址
        yingyongbao: '', //应用宝下载地址
        timeout: 500,
        fallback: '' //换端失败之后跳转的下载链接地址
      }
      const callLib = new CallApp(options)
      callLib.open({
        path: this.hrefUrl,
        callback: function () {
          var msg = '当前应用可能不支持我们唤醒（如果您尚未安装e把手App，点击立即下载试试吧）'
          _this.$refs.myAlertConfirm.show(msg, {
            type: 'alert',
            data: '1'
          })
        }
      })
    },
    userBehavior(type, data) {
      if (type == 'clickConfirm') {
        if (data == '1') {
          this.download()
        }
      }
    },
    download() {
      if (Utils.mobileSys() == 'ios') {
        window.location.href = 'https://apps.apple.com/cn/app/id896945783'
      } else {
        window.location.href = 'https://cloud.hrxjbank.com.cn/download/HRXJBANK.apk'
      }
    }
  }
}
</script>
<style scoped lang='scss'>
.madp-down-page {
  img {
    width: 100%;
  }
  .DownBox {
    width: 100%;
    height: 40%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    text-align: center;
    justify-items: center;
    align-items: center;
    padding-bottom: 10px;
    .btn {
      background: #4a90e2;
      color: #ffffff;
      padding: 8px 120px;
      border-radius: 5px;
      margin-top: 25px;
      margin-bottom: 10px;
    }
    .colorBlue {
      color: #4a90e2;
    }
  }
}
</style>